package com.rongshu.sendmessage.adapter;

import android.content.Context;
import android.content.res.ColorStateList;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;

import com.rongshu.sendmessage.R;
import com.rongshu.sendmessage.bean.CatogryInfoBean;
import com.rongshu.sendmessage.bean.LocationBean;

import java.util.List;

public class ShengAdapter extends BaseAdapter {
    private final List<LocationBean> mList;
    private final Context mContext;
    private final LayoutInflater mInflater;

    public ShengAdapter(Context context, List<LocationBean>list) {
        this.mContext=context;
        this.mList=list;
        this.mInflater= LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Houdler houdler;
        if (convertView==null){
            houdler=new Houdler();
            convertView=mInflater.inflate(R.layout.sheng_item,null);
            houdler.re_item=convertView.findViewById(R.id.re_item);
            houdler.tv_sheng=convertView.findViewById(R.id.tv_sheng);
            houdler.iv_right=convertView.findViewById(R.id.iv_right);
            convertView.setTag(houdler);
        }else{
            houdler= (Houdler) convertView.getTag();
        }
    houdler.tv_sheng.setText(mList.get(position).getName());
        if (mList.get(position).isSelect()){
            houdler.re_item.setBackgroundColor(mContext.getResources().getColor(R.color._0e95f6));
            houdler.tv_sheng.setTextColor(mContext.getResources().getColor(R.color.white));
            houdler.iv_right.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(mContext,R.color.white)));

        }else {
            houdler.re_item.setBackgroundColor(mContext.getResources().getColor(R.color._edf7ff));
            houdler.tv_sheng.setTextColor(mContext.getResources().getColor(R.color.blak_333));
            houdler.tv_sheng.setTextColor(mContext.getResources().getColor(R.color.blak_333));
            houdler.iv_right.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(mContext,R.color.color_black_666666)));

        }
        return convertView;
    }
    private class Houdler{

        public View re_item;
        public TextView tv_sheng;
        public ImageView iv_right;
    }
}
